package com.cucn.ingmall.order.web;

import com.cucn.ingmall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.UUID;

/**
 * @author KouChaoJie
 * @since: 2022/1/18 15:42
 */
@Controller
public class HelloController {
    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/{html}.html")
    public String confirm(@PathVariable("html") String html) {
        return html;
    }

    @GetMapping("/test/createOrder")
    @ResponseBody
    public String createOrderTest() {
        //订单下单成功
        OrderEntity order = new OrderEntity();
        order.setOrderSn(UUID.randomUUID().toString());
        order.setCreateTime(new Date());
        //给mq发送消息
        rabbitTemplate.convertAndSend("order-event-exchange", "order.create.order", order);

        return "ok";
    }
}
